import { ref } from 'vue';
import { adminPermission } from '@/api';

let allPermissionList = [];

export const useAllPermission = () => {
  const allPermission = ref(allPermissionList);

  const initAllPermission = async () => {
    const { data } = await adminPermission();
    if (data) {
      allPermissionList = data;
      allPermission.value = data;
    }
  };

  if (!allPermissionList.length) {
    initAllPermission();
  }
  return {
    allPermission,
    initAllPermission
  };
}